package com.iyunsir.lesson04_url;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class UrlDown {
    public static void main(String[] args) throws Exception{

        URL url = new URL("https://vd2.bdstatic.com/mda-mgjfg11gfvu2i4nn/hd/cae_h264_clips/1626783129944936303/mda-mgjfg11gfvu2i4nn.mp4?auth_key=1629860803-0-0-753925138634b787dc66bb4fb08f3094&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=all");

        // 2.连接到这个资源
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

        InputStream inputStream = urlConnection.getInputStream();

        FileOutputStream fos = new FileOutputStream("f1.mp4");

        byte[] buffer = new byte[1024];
        int len;

        while ((len=inputStream.read(buffer)) != -1){
            fos.write(buffer,0,len); //写出这个数据

        }
        fos.close();
        inputStream.close();
        urlConnection.disconnect();

    }


}
